<template>
	<view class="bgf">
		<diy-navTab
			:activeTab="activeIndex"
			:tabList="tabList"
			@change="changeTab"
		></diy-navTab>
		<workSchedule
			ref="workLogRef"
			v-if="activeIndex === 1"
			:refresh="isRefresh"
		></workSchedule>
		<daily-summary
			ref="dailySummary"
			v-if="activeIndex === 2"
			:type="activeIndex"
			:refresh="isRefresh"
		></daily-summary>
		<daily-suggest
			ref="dailySuggest"
			v-if="activeIndex === 3"
			:type="activeIndex"
			:refresh="isRefresh"
		></daily-suggest>
	</view>
</template>

<script>
import diyNavTab from '@/subPackagesLog/components/diy-navTab/diy-navTab.vue'
import dailySummary from '@/subPackagesLog/pages/workLog/dailySummary.vue'
import workSchedule from '@/subPackagesLog/pages/workLog/schedule/schedule.vue'
import dailySuggest from './compoents/dailySuggest.vue'
export default {
	components: {
		diyNavTab,
		dailySuggest,
		dailySummary,
		workSchedule,
	},
	data() {
		return {
			tabList: [
				{ value: 1, text: '工作日志' },
				{ value: 2, text: '工作汇报' },
			],
			activeIndex: 1, //选中tab页面
			isRefresh: false,
		}
	},
	methods: {
		//切换tab
		changeTab(value) {
			this.activeIndex = value
		},
	},
	onShow() {
		if (this.activeIndex === 1) {
			this.$refs.workLogRef.getList()
		} else if (this.activeIndex === 2) {
			this.$refs.dailySummary && this.$refs.dailySummary.isRefresh()
		} else {
			this.$refs.dailySuggest && this.$refs.dailySuggest.isRefresh()
		}
	},
	onLoad(options) {
		// this.activeIndex = 1
		uni.$on('refreshData', (res) => {
			this.changeTab(Number(res))
			console.log('监听到事件来自 refreshData，携带参数 msg 为：' + res)
			if (res == 1) {
				this.$refs.workLogRef.getList()
			} else if (res == 2) {
				this.$refs.dailySummary.isRefresh()
			} else {
				this.$refs.dailySuggest.isRefresh()
			}
		})
		if (options.tabActive) {
			this.activeIndex = Number(options.tabActive)
		} else {
			this.activeIndex = 1
		}
	},
	onReachBottom() {
		uni.$emit('onReachBottom', this.activeIndex)
	},
	// onReachBottom(e) {
	// 	console.log(e + 'parent')
	// }
}
</script>

<style lang="scss" scoped></style>
